package com.tencent.wepay;
import java.net.URL;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.tencent.wepay.helper.Loader;
import com.tencent.wepay.spi.WepayRepository;
public class WepayManager {
	private static Logger logger=LoggerFactory.getLogger(WepayManager.class);
	private final static String JSAPI_DEFAULT_PROPERTIES="jsapipay.properties";
	private final static String APP_DEFAULT_PROPERTIES="apppay.properties";
	private final static WepayRepository jsapiRespository=new WepayRepository();
	private final static WepayRepository appRespository=new WepayRepository();
	static{
		URL jsapiUrl=Loader.getResource(JSAPI_DEFAULT_PROPERTIES);
		if(jsapiUrl!=null){
			PropertyConfigurator configurator=new PropertyConfigurator();
			configurator.doConfigure(jsapiUrl, jsapiRespository);	
		}
		else{
		    logger.warn(JSAPI_DEFAULT_PROPERTIES +" configuration is not exist");
		}	
		URL appUrl=Loader.getResource(APP_DEFAULT_PROPERTIES);
		if(appUrl!=null){
			PropertyConfigurator configurator=new PropertyConfigurator();
			configurator.doConfigure(appUrl, appRespository);	
		}
		else{
		    logger.warn(JSAPI_DEFAULT_PROPERTIES +" configuration is not exist");
		}	
	}
	public static WepayRepository getJsapiRepository(){
		return jsapiRespository;
	}
	public static WepayRepository getAppRepository(){
		return appRespository;
	}
}

